<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.10"/>
<title>dev: dev/dev/net/TcpConnectionStream.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">dev
   &#160;<span id="projectnumber">0.2</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.10 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('_tcp_connection_stream_8hpp_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">TcpConnectionStream.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/******************************************************************************</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * Name         : TcpConnectionStream.hpp</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> * Author       : 671643387</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * Date         : Aug 27, 2015</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * Description  :</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> *****************************************************************************/</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#ifndef TCPCONNECTIONSTREAM_HPP_</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#define TCPCONNECTIONSTREAM_HPP_</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;</div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &lt;boost/noncopyable.hpp&gt;</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#include &lt;boost/shared_array.hpp&gt;</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#include &lt;boost/pool/pool.hpp&gt;</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor">#include &lt;dev/net/Socket.hpp&gt;</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacedev.html">dev</a></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;{</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;    <span class="keyword">namespace </span>net</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;    {</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;        <span class="keyword">class </span>TcpConnection;</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;</div>
<div class="line"><a name="l00025"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_tcp_connection_stream.html">   25</a></span>&#160;        <span class="keyword">class </span><a class="code" href="classdev_1_1net_1_1_tcp_connection_stream.html">TcpConnectionStream</a> : <span class="keyword">public</span> boost::noncopyable</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;        {</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;        <span class="keyword">protected</span>:</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;            <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classdev_1_1net_1_1_tcp_connection.html">TcpConnection</a>;</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;        <span class="keyword">protected</span>:</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;            <span class="keyword">typedef</span> <a class="code" href="classdev_1_1net_1_1_tcp_connection_stream.html">TcpConnectionStream</a> <span class="keyword">self</span>;</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;        <span class="keyword">protected</span>:</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;            TcpConnectionStream(<a class="code" href="classdev_1_1net_1_1_socket.html">Socket</a>&amp; sock, <span class="keywordtype">size_t</span> <a class="code" href="classdev_1_1net_1_1_tcp_connection_stream.html#a3ae773ddc1f353c00cebf98eb1a9d19e">size</a>);</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;            TcpConnectionStream(<a class="code" href="classdev_1_1net_1_1_socket.html">Socket</a>&amp; sock, boost::shared_array&lt;char&gt; buff, <span class="keywordtype">size_t</span> size);</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;            <span class="keyword">virtual</span> ~TcpConnectionStream();</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;        <span class="keyword">public</span>:</div>
<div class="line"><a name="l00041"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_tcp_connection_stream.html#a89e183a86ce676e7c84a52acad657cb6">   41</a></span>&#160;            <span class="keywordtype">size_t</span> <a class="code" href="classdev_1_1net_1_1_tcp_connection_stream.html#a89e183a86ce676e7c84a52acad657cb6">capacity</a>(<span class="keywordtype">void</span>) { <span class="keywordflow">return</span> buffSize_; }</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;</div>
<div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_tcp_connection_stream.html#a3ae773ddc1f353c00cebf98eb1a9d19e">   47</a></span>&#160;            <span class="keywordtype">size_t</span> <a class="code" href="classdev_1_1net_1_1_tcp_connection_stream.html#a3ae773ddc1f353c00cebf98eb1a9d19e">size</a>(<span class="keywordtype">void</span>) { <span class="keywordflow">return</span> size_; }</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;</div>
<div class="line"><a name="l00053"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_tcp_connection_stream.html#a09c07ca4dd2290ba29c581f061e9cb93">   53</a></span>&#160;            <span class="keywordtype">size_t</span> <a class="code" href="classdev_1_1net_1_1_tcp_connection_stream.html#a09c07ca4dd2290ba29c581f061e9cb93">space</a>(<span class="keywordtype">void</span>) { <span class="keywordflow">return</span> buffSize_ - size_; }</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;        <span class="keyword">protected</span>:</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;</div>
<div class="line"><a name="l00060"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_tcp_connection_stream.html#a36bec7cd4b147e05316930fccdeb214d">   60</a></span>&#160;            <span class="keywordtype">void</span> <a class="code" href="classdev_1_1net_1_1_tcp_connection_stream.html#a36bec7cd4b147e05316930fccdeb214d">reset</a>(<span class="keywordtype">void</span>)</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;            {</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;                begIndex_ = 0;</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;                endIndex_ = 0;</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;                size_ = 0;</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;            }</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;        <span class="keyword">protected</span>:</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;            <span class="keywordtype">size_t</span> read(<span class="keywordtype">char</span>* buf, <span class="keywordtype">size_t</span> length);</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;            <span class="keywordtype">size_t</span> write(<span class="keyword">const</span> <span class="keywordtype">char</span>* buf, <span class="keywordtype">size_t</span> length);</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;        <span class="keyword">protected</span>:</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;            <span class="keywordtype">size_t</span> peek(<span class="keywordtype">char</span>* buf, <span class="keywordtype">size_t</span> length);</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;            <span class="keywordtype">size_t</span> skip(<span class="keywordtype">size_t</span> length);</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;        <span class="keyword">protected</span>:</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;            <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00080"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_tcp_connection_stream.html#a88bcc7529e50e85e41b173601392c2d3">   80</a></span>&#160;            <span class="keyword">self</span>&amp; <a class="code" href="classdev_1_1net_1_1_tcp_connection_stream.html#a88bcc7529e50e85e41b173601392c2d3">operator&gt;&gt; </a>(T&amp; x)</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;            {</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;                read((<span class="keywordtype">char</span>*)&amp;x, <span class="keyword">sizeof</span>(T));</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;                <span class="keywordflow">return</span> *<span class="keyword">this</span>;</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;            }</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;            <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00090"></a><span class="lineno"><a class="line" href="classdev_1_1net_1_1_tcp_connection_stream.html#af0a0f8127849b38d0ba60cb8505ca75d">   90</a></span>&#160;            <span class="keyword">self</span>&amp; <a class="code" href="classdev_1_1net_1_1_tcp_connection_stream.html#af0a0f8127849b38d0ba60cb8505ca75d">operator&lt;&lt; </a>(T&amp; x)</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;            {</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;                assert(<a class="code" href="classdev_1_1net_1_1_tcp_connection_stream.html#a09c07ca4dd2290ba29c581f061e9cb93">space</a>() &gt;= <span class="keyword">sizeof</span>(T));</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;                write((<span class="keyword">const</span> <span class="keywordtype">char</span>*)&amp;x, <span class="keyword">sizeof</span>(T));</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;                <span class="keywordflow">return</span> *<span class="keyword">this</span>;</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;            }</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;        <span class="keyword">protected</span>:</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;            <a class="code" href="classdev_1_1net_1_1_socket.html">Socket</a>&amp; sock_;</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;        <span class="keyword">private</span>:</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;            <span class="keywordtype">size_t</span> buffSize_;</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;            <span class="keywordtype">size_t</span> begIndex_;</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;            <span class="keywordtype">size_t</span> endIndex_;</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;            <span class="keywordtype">size_t</span> size_;</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;            boost::shared_array&lt;char&gt; buffer_;</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;        };</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;    }</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;}</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;</div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;<span class="preprocessor">#endif </span><span class="comment">/* TCPCONNECTIONSTREAM_HPP_ */</span><span class="preprocessor"></span></div>
<div class="ttc" id="namespacedev_html"><div class="ttname"><a href="namespacedev.html">dev</a></div><div class="ttdef"><b>Definition:</b> Atomic.hpp:18</div></div>
<div class="ttc" id="classdev_1_1net_1_1_tcp_connection_stream_html"><div class="ttname"><a href="classdev_1_1net_1_1_tcp_connection_stream.html">dev::net::TcpConnectionStream</a></div><div class="ttdoc">Tcp连接流 </div><div class="ttdef"><b>Definition:</b> TcpConnectionStream.hpp:25</div></div>
<div class="ttc" id="classdev_1_1net_1_1_tcp_connection_stream_html_a3ae773ddc1f353c00cebf98eb1a9d19e"><div class="ttname"><a href="classdev_1_1net_1_1_tcp_connection_stream.html#a3ae773ddc1f353c00cebf98eb1a9d19e">dev::net::TcpConnectionStream::size</a></div><div class="ttdeci">size_t size(void)</div><div class="ttdoc">获取流中数据大小 </div><div class="ttdef"><b>Definition:</b> TcpConnectionStream.hpp:47</div></div>
<div class="ttc" id="classdev_1_1net_1_1_tcp_connection_stream_html_a89e183a86ce676e7c84a52acad657cb6"><div class="ttname"><a href="classdev_1_1net_1_1_tcp_connection_stream.html#a89e183a86ce676e7c84a52acad657cb6">dev::net::TcpConnectionStream::capacity</a></div><div class="ttdeci">size_t capacity(void)</div><div class="ttdoc">获取流能存储的数据大小 </div><div class="ttdef"><b>Definition:</b> TcpConnectionStream.hpp:41</div></div>
<div class="ttc" id="classdev_1_1net_1_1_tcp_connection_html"><div class="ttname"><a href="classdev_1_1net_1_1_tcp_connection.html">dev::net::TcpConnection</a></div><div class="ttdoc">Tcp连接 </div><div class="ttdef"><b>Definition:</b> TcpConnection.hpp:31</div></div>
<div class="ttc" id="classdev_1_1net_1_1_tcp_connection_stream_html_a88bcc7529e50e85e41b173601392c2d3"><div class="ttname"><a href="classdev_1_1net_1_1_tcp_connection_stream.html#a88bcc7529e50e85e41b173601392c2d3">dev::net::TcpConnectionStream::operator&gt;&gt;</a></div><div class="ttdeci">self &amp; operator&gt;&gt;(T &amp;x)</div><div class="ttdoc">>>运算符重载,读到基础类型时请先判断长度是否匹配 </div><div class="ttdef"><b>Definition:</b> TcpConnectionStream.hpp:80</div></div>
<div class="ttc" id="classdev_1_1net_1_1_tcp_connection_stream_html_af0a0f8127849b38d0ba60cb8505ca75d"><div class="ttname"><a href="classdev_1_1net_1_1_tcp_connection_stream.html#af0a0f8127849b38d0ba60cb8505ca75d">dev::net::TcpConnectionStream::operator&lt;&lt;</a></div><div class="ttdeci">self &amp; operator&lt;&lt;(T &amp;x)</div><div class="ttdoc"><<运算符重载,写入时请先判断流时候有足够的空间 </div><div class="ttdef"><b>Definition:</b> TcpConnectionStream.hpp:90</div></div>
<div class="ttc" id="classdev_1_1net_1_1_tcp_connection_stream_html_a36bec7cd4b147e05316930fccdeb214d"><div class="ttname"><a href="classdev_1_1net_1_1_tcp_connection_stream.html#a36bec7cd4b147e05316930fccdeb214d">dev::net::TcpConnectionStream::reset</a></div><div class="ttdeci">void reset(void)</div><div class="ttdoc">重置流 </div><div class="ttdef"><b>Definition:</b> TcpConnectionStream.hpp:60</div></div>
<div class="ttc" id="classdev_1_1net_1_1_tcp_connection_stream_html_a09c07ca4dd2290ba29c581f061e9cb93"><div class="ttname"><a href="classdev_1_1net_1_1_tcp_connection_stream.html#a09c07ca4dd2290ba29c581f061e9cb93">dev::net::TcpConnectionStream::space</a></div><div class="ttdeci">size_t space(void)</div><div class="ttdoc">获取流剩余存储空间 </div><div class="ttdef"><b>Definition:</b> TcpConnectionStream.hpp:53</div></div>
<div class="ttc" id="classdev_1_1net_1_1_socket_html"><div class="ttname"><a href="classdev_1_1net_1_1_socket.html">dev::net::Socket</a></div><div class="ttdoc">套接字 </div><div class="ttdef"><b>Definition:</b> Socket.hpp:23</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_5fc0168d11760b9445bd29fa15d9290f.html">dev</a></li><li class="navelem"><a class="el" href="dir_1ca75188a6074d2843e8fd5d982c3101.html">dev</a></li><li class="navelem"><a class="el" href="dir_cea828ca1984caf90af75ecf8a99968a.html">net</a></li><li class="navelem"><b>TcpConnectionStream.hpp</b></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.10 </li>
  </ul>
</div>
</body>
</html>
